<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/temp.dwt" codeOutsideHTMLIsLocked="false" -->
<%@page import="com.crm.entity.Opportunity,com.crm.entity.Supplier,com.crm.entity.Sources,java.util.*" %>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script type="text/javascript" src="<%=application.getContextPath()%>/js/jquery-1.6.min.js">
</script>

<script language="JavaScript" src="<%=application.getContextPath()%>/js/gen_validatorv4.js"
    type="text/javascript" ></script>
<script typ	e="text/javascript" src="<%=application.getContextPath()%>/js/jquery.validate.js"></script>	
<script type="text/javascript" src="<%=application.getContextPath()%>/js/jquery.validate.min.js"></script>

<!-- InstanceBeginEditable name="doctitle" -->
<!-- InstanceEndEditable -->
<script type="text/javascript" src="<%=application.getContextPath()%>/js/jquery-1.7.2.min.js"></script>
<script language="javaScript" src="<%=application.getContextPath()%>/js/jquery-ui-1.8.20.custom.min.js"></script>

<script type="text/javascript" src="<%=application.getContextPath()%>/js/jquery-1.6.min.js"></script>	
<script type="text/javascript" src="<%=application.getContextPath()%>/js/jquery-ui-1.8.17.custom.min.js"></script>
<link href="<%=application.getContextPath()%>/css/css-crm.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="<%=application.getContextPath()%>/js/colResizable-1.3.min.js"></script>
<!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable -->



<script type="text/javascript"><!--
function sendmail(refid){
	var refno=refid;
	alert("sendmail is caled"+refid);
		 window.open("<%=application.getContextPath()%>/jsp/sendMailPopUp.jsp?reflist="+refno,"SendMail PopUp","scrollbars=1,menubar=1,resizable=0,width=950,height=400");
	
}

function getDivision(){
var orgn=$("#reflist option:selected'").val(); 
var data="refno="+orgn;
$("#ajaxLoader").show();
$.ajax({
	url:" <%=application.getContextPath()%>/importsource/getsource.do",
	mimetype: "text/plain",
	method: "post",
	data: data,
	cache:false,
	success: function(res){
		var e2=document.getElementById('srdiv');
		$('#srdiv')
	    .find('option')
	    .remove()
	    .end()
	   	;
		var tempres=res.split("@");
		var temp=tempres[0].split(",");
		if(temp!= null){
			var o=document.createElement('option');
			o.value="";
			o.text="Select Source";
			e2.options.add(o);
			for(var i=1;i<temp.length;i++){
				var o=document.createElement('option');
				o.value=temp[i];
				o.text=temp[i];
				e2.options.add(o);
			}
		}
		var clientres=tempres[1].split(",");
		 $("#enqclient").html("Client Name Is:<span class='cliendet'>"+clientres[0] +
					"</span>   &nbsp;&nbsp;&nbsp;&nbsp;  Client Division Is:<span class='cliendet'>"+clientres[1]+
					 "</span>    &nbsp;&nbsp;&nbsp;&nbsp;    Client User Is:<span class='cliendet'>"+clientres[2]+"</span>");
					 $("#enqclient").show();
		
	}

}).done(function(html){
	$("#ajaxLoader").hide();
}).fail(function(html){
	$("#ajaxLoader").hide();
	alert("Failed To Load the Data");
});

}




function getParts(){
	var refno=$("#reflist option:selected'").val();
	var source=$("#srdiv option:selected'").val();
if((refno=="")||(refno==null)){
	jAlert("PleaseSelect  One Refrence Number");
	return false;
}
if((source=="")||(source==null)){
	jAlert("PleaseSelect  One Source");
	return false;
}else
	{
	var data="sourceName="+source+"&refno="+refno;
	$("#ajaxLoader").show();
$.ajax({
	url:" <%=application.getContextPath()%>/importsource/getparts.do",
	mimetype: "text/plain",
	method: "post",
	data: data,
	cache:false,
	success: function(res){
		
		$('#sourceRes').html(res);		
	}

}).done(function(html){
	$("#ajaxLoader").hide();
}).fail(function(html){
	$("#ajaxLoader").hide();
	alert("Failed To Load the Data");
});
	}

}
function remsource(){
	var source=$("#srdiv option:selected'").val();
	var refno=$("#reflist option:selected'").val();
	alert("the refrence no "+source);
	if((refno=="Select")){
		jAlert("Please Select  One Refrence Number");
		return false;
	}
	else{
		var data="sourceName="+source+"&refno="+refno;
	$.ajax({
		url:" <%=application.getContextPath()%>/importsource/removesource.do",
		mimetype: "text/plain",
		method: "post",
		data: data,
		cache:false,
		success: function(res){

		}
	}); 
	}
	}
	
	function validate(){
		var refno=$("#reflist").val();
		var source=$("#srdiv").val();
		if(refno==null || refno=="" || source==null || source==""){
			jAlert("Please Select Reference Number And Source");
			return false;
		}
	}
</script>
</head>

<% String sendref=(String)request.getAttribute("currentref");%>
<body <%if(sendref!=null){ %> onload="javascript: sendmail('<%=sendref %>')" <%}%> >
<%List<Opportunity> opprtlist =(List<Opportunity>)request.getAttribute("opprtunity");%>
<%
Set<String> oppList=new HashSet<String>();
if(request.getAttribute("sourceOpprtunity")!=null){
	oppList =(Set<String>)request.getAttribute("sourceOpprtunity");
}%>
<div id="main">

   <%@ include file="common/header.jsp" %>
  <%@ include file="common/submenu.jsp" %>

  
  <div id="content">
  <div id="enqclient" style="display: none;" align="center" class="result_msg"></div>
   <div id="resultMsg"  align="center" class="result_msg">
    <% 
   String msg= request.getParameter("importsrc");
    String curref= request.getParameter("currentref");
    Set<String> sources=(Set<String>) request.getAttribute("sources");
    	if(msg!=null){
    		//System.out.println(msg);
    		out.println(msg);
    	}
    String importmsg=request.getParameter("msgsrc");
    if(importmsg!=null){
    	out.println(importmsg);
    }
    
    %>
    </div>
   <form id="impform" name="impform" action="<%=application.getContextPath()%>/importsource/importsave.do"   method="post">
    <div id="work-area2">
      <div class="heading2">Import From Source </div>
      <div class="boxIFS">
        <table width="100%" border="0" style="height:80px;"  cellspacing="0" cellpadding="0">
          <tr>
            <td width="350" align="left" valign="middle">
            <table width="350" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td align="center"  width=40%" valign="middle">Reference Number </td>
                <td align="left" width="50%" valign="top">
                <select name="reflist" class="form_select" id="reflist">
                 <option value="">Select Refrence</option>
         <% 
              if(opprtlist!=null){
            	  System.out.println("the size of the pr list is "+opprtlist.size());
	      	for(int i=0;i<opprtlist.size();i++){
	      	%>
           <option  <%if(curref!=null && curref.equals(opprtlist.get(i).getRefNum())){ %>selected="selected" <%} %>  value="<%=opprtlist.get(i).getRefNum()%>"><%=opprtlist.get(i).getRefNum()%></option>
                   	<%	}
	              	}%>  	
                </select>
                </td>
              </tr>
        </table></td>
            <td width="350" align="center" valign="middle"><table width="348" border="0" cellspacing="0" cellpadding="0">
               
              <tr>
                <td align="center" valign="middle">Sources</td>
                <td align="left" valign="middle">
               
                <select  class="form_select" name="srdiv" id="srdiv"  onfocus="javascript: getDivision()">
                <option value="">Select Source</option>
                <%
                if(sources!=null){
                	System.out.println("Source List Is:"+sources);
                for(String s:sources){%>
                	<option value="<%=s%>"><%=s%></option>
                <%}}
                %>
                </select>
                </td>
                  
              </tr>
             
            </table></td>
              <td width="200" align="left" valign="middle">
            <table width="200" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td align="left" valign="middle"><input type="button" class="buttonleft" onclick="javascript:return   getParts();" value="Search"/></td>
                <td align="left" valign="middle"></td>
              </tr>
            </table></td>
          </tr>
        </table>
      </div>
      <div id="ajaxLoader" style="display:none" align="center"><img src="<%=application.getContextPath()%>/images/ajax_loader.gif"/></div>
      <table style="height:300px; width:957px;" ><tr><td><div id="sourceRes" class="boxIFS2"></div></td></tr></table> 
    </div>
    </form>
    <!-- InstanceEndEditable -->
  </div>
  <div id="footer"></div>  
</div>
</body>

<!-- InstanceEnd --></html>
<!--  <script>
  $(document).ready(function() {
	  
	 
$('#addsupid').click(function(){	



 $("#extab").append($("#tbodyid").clone()); 
 var colcount=parseInt($("#columnCount").val());
 var initcount=parseInt($("#initCount").val());
 colcount=colcount+initcount;
 $("#columnCount").val(colcount);
 /* alert(colcount); */
});

  
  $('#rsupid').click(function(){
	  var initcount=$("#initCount").val();
	  var colcount=$("#columnCount").val();
	  if(colcount>initcount){
	  $('#extab tr:last').remove();
	  colcount--;
	  $("#columnCount").val(colcount);
	 /*  alert(colcount); */
	  }
  });
	   });
        </script> -->
        
        
<script language="JavaScript" type="text/javascript">
function processFormData(){
  var frmvalidator  = new Validator("impform");
  
  var rowcount=document.getElementById("columnCount");
  var rowc=rowcount.value;
//alert("the rowcount value is"+rowc);
  for(var i=1;i<=rowc;i++)
	  {
  //frmvalidator.addValidation("partno"+i,"req","Please enter PartNo"+i+"");
 // frmvalidator.addValidation("partno"+i,"maxlen=30",	"Max length for partno"+i+" is 30");
 // frmvalidator.addValidation("partno"+i,"alphanumeric","partno"+i+"Only alpha and Numeric chars only");
  
  frmvalidator.addValidation("make"+i,"req","Please enter make row "+i);
 /*  frmvalidator.addValidation("make"+i,"maxlen=30","Max length of make by"+i+" is 30 "); */
  
  frmvalidator.addValidation("rqty"+i,"req","Please enter Required Quantity"+i+" Quantity");
  frmvalidator.addValidation("rqty"+i,"numeric","Required Quantity"+i+"  must be numeric");
  
  
  frmvalidator.addValidation("supplier"+i,"req","supplier"+i+" must not be empty");
/*   frmvalidator.addValidation("supplier"+i,"alphabetic_space","supplier"+i+" must be Alphabets only"); */
  
  frmvalidator.addValidation("uprice"+i,"req","Unit Price"+i+"  must not be empty");
  frmvalidator.addValidation("uprice"+i,"numeric","Unit Price"+i+" value must be numeric");
  
  frmvalidator.addValidation("currency"+i,"req","Currency"+i+" must not be empty");
  
 
  
  /* frmvalidator.addValidation("qtyable"+i,"req","Available Quantity"+i+" must not be empty"); */
  frmvalidator.addValidation("qtyable"+i,"numeric","Available Quantity"+i+" must be numeric");
  
  /* frmvalidator.addValidation("moq"+i,"req"," MOQ"+i+" must not be empty"); */
  frmvalidator.addValidation("moq"+i,"numeric","MOQ"+i+" must be numeric");
  

  
/*   frmvalidator.addValidation("spq"+i,"req","Standard Packing Quantity"+i+" must not be empty"); */
  frmvalidator.addValidation("spq"+i,"numeric","Standard Packing Quantity"+i+" must be numeric");
  
 
  
 
	  }
}
</script>
